package org.JWCB.friend.service.file;

import lombok.extern.slf4j.Slf4j;
import org.JWCB.common.file.domain.OSSResult;
import org.JWCB.common.file.service.OSSService;
import org.JWCB.friend.util.FileValidationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@Service
public class FileService {

    @Value("${file.oss.avatarDir}")
    private String avatarDir;


    @Autowired
    private OSSService ossService;

    /**
     * 用户头像上传
     */
    public OSSResult avatarUpload(MultipartFile file) throws Exception {
        FileValidationUtils.imageFileValid(file);
        return ossService.uploadFile(file, avatarDir);
    }

}
